cmake_minimum_required(VERSION 3.10.2)

project(mydecoder)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -g -Wall -Werror -Wno-deprecated")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -DDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")

set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
set(EXTERNAL_DIR ${ROOT_DIR}/external) 


# 配织依赖路径
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")

elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
    set(TARGET_PLATFORM android)
    set(FFMPEG_PATH ${EXTERNAL_DIR}/ffmpeg/${TARGET_PLATFORM}/${CMAKE_ANDROID_ARCH_ABI})

    include_directories(${FFMPEG_PATH}/include ${FFMPEG_PATH}/include/libffmpeg)
    link_directories(${FFMPEG_PATH})
    message("bruce >>> FFMPEG_PATH=${FFMPEG_PATH}")
endif()


if (NOT DEFINED LIB_INSTALL_DIR)
    set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib")
endif()

if (NOT DEFINED INCLUDE_INSTALL_DIR)
    set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include")
endif()

set(SRC_LIST
    common/AVBuffer.cpp
    video/video_decoder/video_decoder_factory.cpp
    video/video_decoder/video_decoder.cpp
    video/video_decoder/ffmpeg_video_decoder.cpp
)

if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
    add_library(mydecoder STATIC ${SRC_LIST})

    install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/ios"
        DESTINATION "${IOS_PRODUCT_PATH}/Headers/"
        FILES_MATCHING
        PATTERN "*.H*"    
    )   
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
    add_library(mydecoder SHARED ${SRC_LIST})

    target_include_directories(mydecoder PUBLIC
        common
        video/video_common
        video/video_decoder
        )
    target_link_libraries(mydecoder ijkffmpeg)

    install(TARGETS mydecoder 
        LIBRARY DESTINATION ${LIB_INSTALL_DIR})
    install(DIRECTORY video/video_decoder/ DESTINATION ${INCLUDE_INSTALL_DIR})
endif()